/**
 * 上海中赢金融信息服务有限公司
 * Copyright (c) 2016-2026 hmc,Inc.All Rights Reserved.
 */
package com.sys.midware.hbase.config;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sys.midware.config.core.ConfigContainer;
import com.sys.midware.config.core.ConfigKey;
import com.sys.midware.config.model.BNode;
import com.sys.midware.logger.Logger;
import com.sys.midware.logger.LoggerFactory;

/**
 * 
 * <b>ClassName：</b> ConfigMongoUtil <br/>
 * <b>Description：</b> 获取配置信息工具类 <br/>
 * <b>@author：</b> mobing <br/>
 * <b>@date：</b> 2015年10月19日 下午2:55:02 <br/>
 * <b>@version: </b> <br/>
 */
public class BHBaseConfigUtil {
    private static final Logger logger = LoggerFactory.getLogger(BHBaseConfigUtil.class);

    /**
     * ConfigContainer instance
     */
    private static ConfigContainer cfg = ConfigContainer.getInstance(ConfigKey.ConfigFile.CONFIG_FILE_ROOT);

    private static boolean inited;

    public static void initConfig() {
        if (inited) {
            return;
        }
        logger.info("开始初始化hbase配置...");
        
        Map<String, BHBaseConfig> hbaseConfigCached = new HashMap<String, BHBaseConfig>();
        List<BNode> bnodeList = cfg.getBNodeList();
        for (BNode b : bnodeList) {
            String nodeFor = b.getNodeFor();
            if("hbase".equals(nodeFor)){
                BHBaseConfig hbaseConfig = new BHBaseConfig();
                hbaseConfig.setNodeName(b.getNodeName());
                hbaseConfig.setNodeType(b.getNodeType());
                hbaseConfig.setHbaseHost(b.getNodeParamStr(ConfigKey.HBase.KEY_HBASE_HOST));
                hbaseConfig.setHbasePort(b.getNodeParamInteger(ConfigKey.HBase.KEY_HBASE_PORT));
                hbaseConfig.setZKCluster(b.getNodeParamStr(ConfigKey.HBase.KEY_HBASE_ZOOKEEPER_CLUSTER));
                hbaseConfig.setZKPort(b.getNodeParamInteger(ConfigKey.HBase.KEY_HBASE_ZOOKEEPER_PORT));
                //属性配置
                hbaseConfig.setHbaseAutoflush(cfg.getParamBoolean(ConfigKey.HBase.KEY_HBASE_CLIENT_AUTOFLUSH));
                hbaseConfig.setHbaseCFBloomType(cfg.getParamString(ConfigKey.HBase.KEY_HBASE_CLIENT_CF_BLOOMTYPE));
                hbaseConfig.setHbaseCFCompressionAlgorithm(
                        cfg.getParamString(ConfigKey.HBase.KEY_HBASE_CLIENT_CF_COMPRESSIONALGORITHM));
                hbaseConfig.setHbaseCompaction(cfg.getParamBoolean(ConfigKey.HBase.KEY_HBASE_CLIENT_COMPACTION));
                hbaseConfig
                        .setHbaseEnableBlockCache(cfg.getParamBoolean(ConfigKey.HBase.KEY_HBASE_CLIENT_ENABLEBLOCKCACHE));
                hbaseConfig.setHbaseQueryBatch(cfg.getParamInteger(ConfigKey.HBase.KEY_HBASE_CLIENT_QUERY_BATCH));
                hbaseConfig.setHbaseQueryMaxResultSize(
                        cfg.getParamInteger(ConfigKey.HBase.KEY_HBASE_CLIENT_QUERY_MAXRESULTSIZE));
                hbaseConfig.setHbaseScannerCaching(cfg.getParamInteger(ConfigKey.HBase.KEY_HBASE_CLIENT_SCANNER_CACHING));
                hbaseConfig.setHbaseWal(cfg.getParamString(ConfigKey.HBase.KEY_HBASE_CLIENT_WAL));
                hbaseConfig.setHbaseWriteBuffer(cfg.getParamInteger(ConfigKey.HBase.KEY_HBASE_CLIENT_WRITE_BUFFER));
                
                hbaseConfigCached.put(b.getNodeName(), hbaseConfig);
            }
        }
        BHBaseConfigMapHolder.put(hbaseConfigCached);
        inited = true;
        logger.info("hbase config has bean inited!");
    }

}
